package com.heima.a07_demo.server.controller;

import com.heima.a07_demo.common.result.Result;
import com.heima.a07_demo.pojo.dto.DiagnosisBatchDTO;
import com.heima.a07_demo.pojo.dto.DiagnosisDTO;
import com.heima.a07_demo.pojo.vo.DiagnosisRecordPageVO;
import com.heima.a07_demo.pojo.vo.DiagnosisReportVO;
import com.heima.a07_demo.pojo.vo.DiagnosisVO;
import com.heima.a07_demo.server.service.DiagnosisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@Slf4j
public class DiagnosisController {
    @Autowired
    private DiagnosisService diagnosisService;

    /*
    * 单个诊断
    * */
    @PostMapping("/diagnose")
    public Result<DiagnosisVO> diagnosis(@RequestBody DiagnosisDTO diagnosisDTO){
        log.info("打印数据patientId：{},doctorId：{}，imagePaths：{}",
                diagnosisDTO.getPatientId(),diagnosisDTO.getDoctorId(),diagnosisDTO.getImagePaths());

        Long patientId=diagnosisDTO.getPatientId();
        Long doctorId=diagnosisDTO.getDoctorId();
        ArrayList<String> imagePaths=diagnosisDTO.getImagePaths();
        DiagnosisVO diagnosisVO=new DiagnosisVO();
        //进行诊断
        diagnosisVO=diagnosisService.diagnosis(patientId,doctorId,imagePaths);
        return Result.success(diagnosisVO);

    }
    /*
    * 批量诊断
    * */
    @PostMapping("/diagnose/batch")
    public Result<ArrayList<DiagnosisVO>> diagnosisBatch(@RequestBody DiagnosisBatchDTO diagnosisBatchDTO){


        ArrayList<Long> patientIds=diagnosisBatchDTO.getPatientIds();
        Long doctorId= diagnosisBatchDTO.getDoctorId();
        ArrayList<String> imagePaths=diagnosisBatchDTO.getImagePaths();
        ArrayList<DiagnosisVO> results=new ArrayList<DiagnosisVO>();
        //进行批量诊断
        results=diagnosisService.diagnosisBatch(patientIds,doctorId,imagePaths);
        return Result.success(results);

    }
    /*
    * 查询诊断报告
    * */
    @GetMapping("/diagnose/report")
    public Result<DiagnosisReportVO> getDiagnosisReport(@RequestParam("patientId") Long patientId) {
        DiagnosisReportVO report = diagnosisService.getDiagnosisReport(patientId);
        return Result.success(report);
    }
    /**
     * 分页展示诊断记录
     * @param beginTime 起始时间
     * @param endTime 结束时间
     * @param diagnosisType 疾病类型
     * @param page 页码
     * @param pageSize 每页记录数
     * @return 分页查询结果
     */
    @GetMapping("/diagnosisrecord/show/page")
    public Result<DiagnosisRecordPageVO> selectDiagnosisRecordByPage(
            @RequestParam(required = false) String beginTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String diagnosisType,
            @RequestParam int page,
            @RequestParam int pageSize
    ) {
        DiagnosisRecordPageVO result = diagnosisService.selectDiagnosisRecordByPage(
                beginTime,
                endTime,
                diagnosisType,
                page,
                pageSize
        );
        return Result.success(result);
    }

}
